package com.nstar.orderexpress.view
{
	import mx.containers.TitleWindow;
	import mx.events.FlexEvent;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	import mx.controls.Button;
	import flash.events.MouseEvent;
	import com.nstar.orderexpress.model.Model;
	import com.nstar.base.util.Logger;
	import mx.controls.TextInput;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;

	public class LoginClass extends TitleWindow
	{
		public var btnOK:Button;
		public var btnCancel:Button;
		public var txtUserName:TextInput;
		public var txtPassword:TextInput;
		
		private var loggined:Boolean = false;
		
		private var model:Model = Model.getInstance();
		private var logger:Logger = Logger.getInstance();
		
		public function LoginClass()
		{
			//TODO: implement function
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
			this.addEventListener(KeyboardEvent.KEY_DOWN,keydownHandler);
		}
		
		private function init(event:FlexEvent):void{
			this.addEventListener(CloseEvent.CLOSE,closeHandler);
			btnOK.addEventListener(MouseEvent.CLICK,okHandler);
			btnCancel.addEventListener(MouseEvent.CLICK,closeHandler);
			txtUserName.setFocus();
		}
		
		private function closeHandler(event:*):void{
			PopUpManager.removePopUp(this);
		}
		
		private function okHandler(event:MouseEvent):void{
			loggined = true;
			model.mainApp.infoPanelView.txtUserName.text = txtUserName.text;
			model.mainApp.infoPanelView.cboUserType.selectedIndex = 1;
			model.mainApp.infoPanelView.lbLogin.dataProvider[0] = "注销";
			
			closeHandler(null);
		}
		
		private function keydownHandler(event:KeyboardEvent):void{
			switch (event.keyCode){
				case Keyboard.ENTER:
					okHandler(null);
					break;
			}
		}
	}
}